The present invention relates to a real-time system, and more particularly, to an apparatus and method for measuring a CPU occupancy rate of a task in a real-time system.
Generally, a real-time system, such as a digital cross-connect system (DCS), loads software to its central process unit (CPU) to construct or monitor a transmission line. The software processes a plurality of tasks, such as switching, alarming, and the like in real time. Each of the tasks has its own priority and cycle set to be absolutely executed in the determined cycle. Hence, the real-time system executing a plurality of tasks needs to carry out a task schedule of assignment priorities, execution times, and proper cycles of the tasks.
The schedule used in the real-time system is divided into a rate monotonic (RM) scheduling according to the priority of the corresponding task, an earliest deadline first EDF) scheduling, and a weighted fair queuing (WFQ) scheduling, which shares CPU according to a schedule ratio.
FIG. 1 illustrates a schematic block diagram of a real-time system by RM scheduling according to a related art. As shown in FIG. 1, a real-time system 10, a DCS includes a ROM 11 storing a scheduling-related program, a RAM 12 downloading a program read by the ROM 11, and a CPU 13 executing a plurality of tasks in accordance with the program downloaded to the RAM 12. The DCS carries out a data communication with an external transmission system 20.
In operation of the above described real-time system, the CPU 13 downloads the program relating to an RM scheduling from the ROM 11 to the RAM 12, and then executes a task associated with the RM scheduling system in accordance with the corresponding downloaded program.
In the case of more than one task associated with the RM scheduling system, the priorities of tasks A, B, and C shown in FIG. 2 are set as task A greater than task B greater than task C by the RM scheduling. The CPU 13 executes the task A of the highest priority and, subsequently carries out task B and task C sequentially. While the task C is being executed and task B with higher priority than task C needs to be executed, the CPU 13 will stop executing task C and execute task B first, then carries out the rest of the task C, which was previously processed and not yet furnished. By the same token, when a plurality of tasks are waiting to be executed by the RM scheduling system, the real-time system should be designed to carry out all of the tasks in balance based on their priorities, cycles, and a quantity of execution contents.
For instance, referring to FIG. 3, if the cycles of the tasks are called Ta, Tb, and Tc and execution times of the tasks are set up as ta, tb, and tc, respectively, the CPU occupancy rates of the tasks A, B, and C become ta/Ta, tb/Tb, and tc/Tc, respectively. In this case, a total CPU occupancy rate (ta/Ta+tb/Tb+tc/Tc) of the tasks should be smaller than 1.
However, the fact that the total CPU occupancy rate is smaller than 1 fails to secure that each of the tasks is executed in its cycle properly. This is because tasks having low priority fail to be executed in their cycles and very too often are delayed if some tasks having high priority occupy the corresponding cycle. For instance, if the tasks A and B having higher priorities occupy the CPU 13 already, the task C having the lowest priority, as shown in the entire tasks of FIG. 3, fails to be executed in its cycle Tc, and this failure is hardly detected.
Moreover, even if several tasks are properly executed in their cycles in the real-time system according to the related art, it is impossible to measure the CPU occupancy rate of each of the tasks. It is also difficult to measure the CPU occupancy rate when the CPU is demanded to carry out lots of work or to generate a supplementary routine. The task usually fails to share the CPU with other tasks.
Unfortunately, the real-time system according to the related art is unable to check if each task is correctly executed in accordance with the schedule or to detect how much the CPU occupancy rate of the corresponding task is. As a result, the real-time system fails to attain a precise balance of the respective tasks and to reflect the CPU occupancy rate in terms of a task design and debugging.
The above references are incorporated by reference herein where appropriate for appropriate teachings of additional or alternative details, features and/or technical background.
An object of the invention is to solve at least the above problems and/or disadvantages and to provide at least the advantages described hereinafter.
An object of the present invention is to provide an apparatus and method that are capable of measuring a CPU task occupancy rate in a real-time system. Another object of the present invention is to provide an apparatus and method that are capable of inspecting if each task is properly executed in its own execution cycle.
In order to achieve at least the above objects in whole or in parts, there is provided an apparatus for measuring a CPU task occupancy rate in a real-time system, including a task register unit for registering a task to be measured in flag bits, a task selecting module for selecting and outputting a bit address of the task having a high priority flag bit among the flag bits, a count signal generating unit for processing the bit address inputted from the task selecting module to generate a count signal. The apparatus also includes a count unit for counting an execution time of the task in accordance with the count signal, and a CPU for setting the flag bit when the task is executed and calculating an execution number. The CPU task occupancy rate is calculated based on a count value of the count unit.
In another aspect of the present invention, an apparatus for measuring a CPU task occupancy rate of a real-time system includes a task register unit for registering a task to be measured in flag bits, a register unit for storing a bit address of the registered task, a task selecting module for selecting and outputting an address of the flag bit having a high priority among the flag bits, which are set in the task register unit. The apparatus further includes a logical operation unit for operating the bit address outputted from the register unit and the address outputted from the task selecting module to generate a count signal, a count unit for counting an execution time of the task in accordance with the count signal, and a CPU setting the flag bit when the task is executed and calculating an execution number. The CPU task occupancy rate is calculated based on a count value of the count unit.
In a further aspect of the present invention, an apparatus for measuring a CPU task occupancy rate of a real-time system includes a task register unit for registering a task to be measured in flag bits, a task selecting module for selecting and outputting an address of the flag bit having a high priority among the flag bits, which are set in the task register unit. There is also provided a decoder for decoding the bit address outputted from the task selecting module to generate a count signal, a count unit for counting an execution time of the task based on the count signal of the decoder, and a CPU setting the flag bit when the task is executed and calculating an execution number. The CPU task occupancy rate is calculated based on a count value of the count unit.
Further, another aspect of the present invention, a method of measuring a CPU task occupancy rate of a real-time system includes registering a task in a flag bit, setting the flag bit when the task is executed, and outputting an address of the flag bit closer to a least significant bit(LSB) among at least one address of at least one set flag bit. The method also includes generating a count signal by decoding the outputted address, and calculating the CPU task occupancy rate by counting an execution time of the task in accordance with the count signal.
Additional advantages, objects, and features of the invention will be set forth in part in the description which follows and in part will become apparent to those having ordinary skill in the art upon examination of the following or may be learned from practice of the invention. The objectives and other advantages of the invention may be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.